package com.lightjet.macross.base.gateway.controller;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : lijia
 * @version : 1.0 2019-10-31 15:33
 * description : 雪崩控制器
 */
@RestController
@RequestMapping("/")
@Log
public class FallBackController {

    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("fallback")
    public Map<String,Object> FallBack()
    {
        log.info("crash fallback!");
        Map<String,Object> map = new HashMap<>();
        map.put("code","500");
        map.put("message","当前服务不可用");
        return map;
    }

    @RequestMapping(value = "clientaccesspolicy.xml",produces = MediaType.APPLICATION_XML_VALUE)
    public String SilverlightAccessPolicy()
    {
        log.info("silverlight project called!");
        return "<?xml version=\"1.0\" encoding=\"utf-8\" ?><access-policy><cross-domain-access><policy><allow-from http-request-headers=\"*\"><domain uri=\"*\"></domain></allow-from><grant-to><resource path=\"/\" include-subpaths=\"true\"></resource></grant-to></policy></cross-domain-access></access-policy>";
    }

    @RequestMapping(value = "crossdomain.xml",produces = MediaType.APPLICATION_XML_VALUE)
    public String CrossDomain()
    {
        log.info("crossdomain.xml called!");
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE cross-domain-policy SYSTEM  \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\" ><cross-domain-policy><site-control permitted-cross-domain-policies=\"all\" /><allow-access-from domain=\"*\" /><allow-http-request-headers-from domain=\"*\" headers=\"*\"/></cross-domain-policy>";
    }
}
